package cn.web.web_module.controller;

import cn.itcast.pojo.horseman;
import cn.itcast.util.ResponseEntity;
import cn.web.web_module.service.UserBindHorsemanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.List;
import java.util.Map;

/**
 * @Author: 张松
 * @Description:
 * @Date: Created in 18:52 2020/12/29
 * @Modified By:
 */
@RestController
@RequestMapping(value = "userBindHorseman",produces = "application/json;charset=UTF-8")
public class UserBindHorsemanController {

    @Resource
    private UserBindHorsemanService userBindHorsemanService;


    @PostMapping("findHorsemanAccount")
    public ResponseEntity<List> findHorsemanAccount( @RequestBody Map<String,String> map){
        if (map.get("horsemanPhone").isEmpty()||map.get("horsemanPhone").length()==0){
            return new ResponseEntity(400,"数据不能为空");
        }
        List<horseman> horsemanPhone = userBindHorsemanService.findHorsemanAccount(map.get("horsemanPhone"));
        if (!horsemanPhone.isEmpty()||horsemanPhone.size()>0){
            return new ResponseEntity(horsemanPhone);
        }
        return new ResponseEntity("没有该骑手信息").error_300();
    }

    @PostMapping("bindHorsemanAccount")
    public ResponseEntity<List> bindHorsemanPhone(@RequestBody Map<String,String> map){

        if (map.get("userOpenid").isEmpty()||map.get("userOpenid").length()==0){
            return new ResponseEntity<>(400,"用户数据不能为空");
        }
        if (map.get("horsemanPhone").isEmpty()||map.get("horsemanPhone").length()==0){
            return new ResponseEntity<>(400,"骑手账号不能为空");
        }
        Integer integer = userBindHorsemanService.bindHorsemanPhone(map.get("userOpenid"), map.get("horsemanPhone"));
        if (integer>0){
            return new ResponseEntity<>(200);
        }
        return new ResponseEntity<>(300);
    }


    @PostMapping("relieveUserBindHorseman")
    public  ResponseEntity relieveUserBindHorseman(@RequestBody Map<String,String> map){
        String userOpenId = map.get("userOpenId");
        if (userOpenId.isEmpty()||userOpenId.length()==0){
            return new ResponseEntity(300,"请传入需要解绑的用户");
        }
        Integer integer = userBindHorsemanService.relieveUserBindHorseman(userOpenId);
        if (integer>0){
            return new ResponseEntity(200,"解绑成功");
        }
        return new ResponseEntity(300,"解绑失败,请重试");
    }


}
